//文件下载权限申请
$(".download-icon").on('click', function () {
    //询问框
    layer.confirm('权限不足，是否申请更高权限？', {
        title: '提示信息',
        btn: ['申请', '取消'] //按钮
    }, function () {
        layer.msg('申请成功', {
            icon: 1
        });
    });
});


//文件上传统一字段
function showfile() {
    $(".hidefile").show();
};

function hidefile() {
    $(".hidefile").hide();
};
//文件下载权限事件
function down(id) {
    //询问框
    layer.confirm('权限不足，是否申请更高权限？', {
        title: '提示信息',
        btn: ['申请', '取消'] //按钮
    }, function () {
        layer.msg('申请成功', {
            icon: 1
        });
    });
};
//查询线索信息
function findStageInfo() {
    $certusUtils.ajax("findProStageInfo1", {
        "proId": proId
    }, function (response) {
        var data = response.data.stageList;
        if (data.pro_no == undefined) {
            $("#hasLxInfo").hide();
            $("#noLxInfo").show();
        }else{
            $("#hasLxInfo").show();
            $("#noLxInfo").hide();

            $("#proArea").html(data.pro_area);
            var proType = data.pro_type;
            $("#cusName").html(data.cus_name);
            $("#proName").html(data.pro_name);
            $("#proNo").html(data.pro_no);
            $("#clueDesc").html(data.clue_desc);
            $("#cusPolicy").html(data.cus_policy);
            $("#clueApplyDesc").html(data.clue_apply_desc);
            $("#competitor").html(data.competitor);
            if (proType == "ZL") {
                $("#proType").html("战略类");
            } else if (proType == "YF") {
                $("#proType").html("研发类");
            } else if (proType == "XS") {
                $("#proType").html("销售类");
            } else if (proType == "BM") {
                $("#proType").html("部门类");
            } else if (proType == "SW") {
                $("#proType").html("事务类");
            } else {
                $("#proType").html("测试类");
            }
            if (proType == "XS") {
                // $("#showFinish").hide();
                $("#showVersion").hide();
                $("#divineSignDate").html(data.divine_sign_date);
                $("#divineHkDate").html(data.divine_hk_date);
                $("#cusPolicy").html(data.cus_policy);
                $("#competitor").html(data.competitor);
                var isCompare = data.is_compare;
                if (isCompare == 1) {
                    $("#isCompare").html("有");
                } else {
                    $("#isCompare").html("无");
                }

            } else if (proType == "ZL" || proType == "SW" ||
                proType == "BM") {
                $("#showArea").hide();
                $("#showCus").hide();
                $("#showCompare").hide();
                $("#showSign").hide();
                $("#showHk").hide();
                $("#showPolucy").hide();
                $("#showCompe").hide();
                $("#showVersion").hide();
                // $("#divineFinishTime").html(data.dfTime);
                $("#showCompe").hide();
            } else {
                $("#showArea").hide();
                $("#showCus").hide();
                $("#showCompare").hide();
                $("#showSign").hide();
                $("#showHk").hide();
                $("#showPolucy").hide();
                $("#showCompe").hide();
                // $("#showFinish").hide();
                var date = new Date(data.divine_version_time);
                var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
                $("#divineVersionTime").html(content);
                $("#showCompe").hide();
            }

            var proLv = data.pro_lv;
            if (proLv == 3) {
                $("#proLv").html("高");
            } else if (proLv == 2) {
                $("#proLv").html("中");
            } else {
                $("#proLv").html("低");
            }
            var nodeFlag = data.node_flag;
            var step = 0;
            if (nodeFlag == 1) {
                step = 1;
            } else if (nodeFlag == 2) {
                step = 2;
            } else if (nodeFlag == 3 || nodeFlag == 4) {
                step = 3;
            } else {
                step = 1;
            }
            stepBar.init("stepBar", {
                step: step,
                change: false,
                animation: true
            });

            // 重置流程效果宽度
            var barWidth = $("#stepBar").width();
            var itemWidth = Math.floor((barWidth * 0.9) / (3 - 1));

            $("#stepBar").find(".ui-stepLayout").width(Math.floor(barWidth * 0.9 + itemWidth));
            $("#stepBar .ui-stepInfo").width(itemWidth);
            $("#stepBar").find(".ui-stepLayout").css({
                "margin-left": -Math.floor(itemWidth / 2) + 10
            });

            var calc = 100 / (3 - 1);
            var curProcessWidth = calc * (step - 1) + "%";
            $("#stepBar").find(".ui-stepProcess").width(curProcessWidth);
        };

        //人天预估
        var rlColumns = [{
            id: 'roleName',
            title: '角色',
            type: 'string',
            columnClass: 'text-center'
        },{
            id: 'level',
            title: '级别',
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '';
                if (value=="1"){
                    content = "低";
                }else if (value=="2"){
                    content = "中";
                }else{
                    content = "高";
                }
                return content;
            }
        },{
            id: 'beginTime',
            title: '开始时间',
            type: 'date',
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'endTime',
            title: '结束时间',
            type: 'date',
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
        },{
            id: 'rtNum',
            title: '人天',
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'comments',
            title: '说明',
            type: 'string',
            columnClass: 'text-center',
        }];
        var rlOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '人力成本列表',
            datas: response.data.rtList,
            columns: rlColumns,
            gridContainer: 'rtContainer',
        };
        var rlGrid = $.fn.dlshouwen.grid.init(rlOption);
        rlGrid.load();

        //涉及文件
        var wjColumns = [{
            id: 'productName',
            title: '文件名称',
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'comments',
            title: '说明',
            type: 'string',
            columnClass: 'text-center',
        }];
        var wjOption = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '人力成本列表',
            datas: response.data.wjList,
            columns: wjColumns,
            gridContainer: 'wjContainer'
        };
        var wjGrid = $.fn.dlshouwen.grid.init(wjOption);
        wjGrid.load();
    });

    $certusUtils.ajax("findNodeInfoList", {
        "proId": proId
    }, function (response) {
        var html = "";
        var data = response.data;
        for (var i = 0; i < data.length; i++) {
            html += "<li><span>" + data[i].user_name + "</span><span>" + data[i].createTime + "</span>";
            if (data[i].opinion_msg == "" || data[i].opinion_msg == null || data[i].opinion_msg == undefined){
                data[i].opinion_msg = "无";
            }
            if (data[i].node_flag == 1 || data[i].node_flag == 5) {
                html += "<span>发起申请</span>";
            }
            if (data[i].node_flag == 2) {
                html += "<span>退回，审批意见：" + data[i].opinion_msg + "</span>";
            }
            if (data[i].node_flag == 3) {
                html += "<span>审批通过，审批意见：" + data[i].opinion_msg + "</span>";
            }
            if (data[i].node_flag == 4) {
                html += "<span>审批不通过，审批意见：" + data[i].opinion_msg + "</span>";
            }
            if (data[i].node_flag == 6) {
                html += "<span>同意申请，审批意见：" + data[i].opinion_msg + "</span>";
            }
            html += "</li>";
        }
        $("#tpNode").append(html);
    });

    $certusUtils.ajax("findBugetInfo", {
        "proId": proId,
        "code": "XS"
    }, function (response) {
        var other1Columns = [{
            id: 'buget_phase',
            title: '阶段',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
        }, {
            id: 'buget_type',
            title: '预算类型',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
        }, {
            id: 'buget',
            title: '预算金额',
            type: 'string',
            width: 150,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var content = '￥' + value + '元';
                return content;
              }
        }, {
            id: 'budget_begin',
            title: '开始时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
            resolution: function (value, record) {
				var content = "";
				if (value != null && value != "") {
					var date = new Date(value);
					content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
				}
				return content;
			}
        }, {
            id: 'budget_end',
            title: '结束时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype: 'time_stamp_ms',
            columnClass: 'text-center',
            resolution: function (value, record) {
				var content = "";
				if (value != null && value != "") {
					var date = new Date(value);
					content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
				}
				return content;
			}
        }, {
            id: 'comments',
            title: '费用说明',
            type: 'string',
            columnClass: 'text-left'
        }];
        var other1Option = {
            lang: 'zh-cn',
            ajaxLoad: false,
            extraWidth: 20,
            // loadURL:'url',
            exportFileName: '其他费用',
            datas: response.data,
            columns: other1Columns,
            gridContainer: 'other1Container',
            tools: ''
        };
        var other1Grid = $.fn.dlshouwen.grid.init(other1Option);
        other1Grid.load();
    });
};